<?php
/**
 * 控制器公共类(基础类)文件
 */

namespace app\index\controller;

use think\Controller;
use think\Request;
use app\index\model\Category;

/**
 * 控制器基础类
 *
 * @category index
 * @package  Controller
 * @author   huwhois <huwhois@163.com>
 */

class Base extends Controller
{
    protected $category_model;

    /**
     * $request Tp5.0 的请求响应对象
     */
    public function __construct(Request $request = null)
    {
        parent::__construct($request);

        $this->category_model = new Category();

        $c = strtolower(request()->controller());
        $a = strtolower(request()->action());
        
        $this->assign('controller', $c);
        $this->assign('action', $a);

        /**
         *  加载第三方脚步
         */
        $script = new \app\admin\model\ScriptConfig();

        $data_script = $script->find(1);

        $this->assign('data_script', $data_script);

        /**
         * 站点信息 logo 联系方式 地址等
         */
        $site = new \app\admin\model\SiteConfig();

        $data_site = $site->where('status', 1)->column('field, value');
        
        $this->assign('data_site', $data_site);


        /**
         * 首页顶部广告加载
         */
        $advert = new \app\admin\model\Advert();

        $data_adtop = $advert->where('typeid', 2)->find();
        $this->assign('data_adtop', $data_adtop);


        /**
         * 栏目读取
         */
        //关于我们
        $aboutus = new \app\admin\model\Aboutus();

        $nav_aboutus = $aboutus->where('id', '<>', 1)->column('id, title');
        $this->assign('nav_aboutus', $nav_aboutus);

        //施工管理
        $nav_build = $this->category_model->where('pid', 51)->column('id, name');
        $this->assign('nav_build', $nav_build);

        //设计团队
        $nav_designer = $this->category_model->where('pid', 61)->column('id, name');
        $this->assign('nav_designer', $nav_designer);

        //全案设计
        $nav_ensemble = $this->category_model->where('pid', 21)->column('id, name');
        $this->assign('nav_ensemble', $nav_ensemble);

        //软装设计
        $nav_soft = $this->category_model->where('pid', 31)->column('id, name');
        $this->assign('nav_soft', $nav_soft);

        //服务中心
        $server = new \app\admin\model\ServerCenter();
        $nav_server = $server->where('status', 1)->column('id, title');
        $this->assign('nav_server', $nav_server);
    }
}
